Android Dependency Injection (Hilt)
Priority: P0
Implementation Guidelines
Setup
- App: Must annotate
Applicationclass with@HiltAndroidApp. - Entries: Annotate Activities/Fragments with
@AndroidEntryPoint.
Modules
- Binding: Use
@Binds(abstract class) over@Provideswhen possible (smaller generated code). - InstallIn: Be explicit (
SingletonComponent,ViewModelComponent).
Construction
- Constructor Injection: Prefer over Field Injection (
@Inject constructor(...)). - Assisted Injection: Use for runtime parameters (
@AssistedInject).
Anti-Patterns
- Component Manual Creation:
**No Manual Dagger**: Use Hilt Standard. - Field Inject in Logic:
**No Field Inject**: Only in Android Components.